﻿using Coldairarrow.Business.Apk;
using Coldairarrow.Entity.Apk;
using Coldairarrow.Util;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Coldairarrow.Api.Controllers.Apk
{
    [Route("/Apk/[controller]/[action]")]
    public class Apk_EditionController : BaseApiController
    {
        #region DI

        public Apk_EditionController(IApk_EditionBusiness apk_EditionBus)
        {
            _apk_EditionBus = apk_EditionBus;
        }

        IApk_EditionBusiness _apk_EditionBus { get; }

        #endregion

        #region 获取

        [HttpPost]
        public async Task<PageResult<Apk_Edition>> GetDataList(PageInput<ConditionDTO> input)
        {
            return await _apk_EditionBus.GetDataListAsync(input);
        }

        [HttpPost]
        public async Task<Apk_Edition> GetTheData(IdInputDTO input)
        {
            return await _apk_EditionBus.GetTheDataAsync(input.id);
        }

        #endregion

        #region 提交

        [HttpPost]
        public async Task SaveData(Apk_Edition data)
        {
            if (data.Id.IsNullOrEmpty())
            {
                InitEntity(data);

                await _apk_EditionBus.AddDataAsync(data);
            }
            else
            {
                await _apk_EditionBus.UpdateDataAsync(data);
            }
        }

        [HttpPost]
        public async Task DeleteData(List<string> ids)
        {
            await _apk_EditionBus.DeleteDataAsync(ids);
        }

        /// <summary>
        /// 获取PDA的apk最新版本
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [NoCheckJWT]
        public async Task<Apk_Edition> GetApkEdition()
        {
            return await _apk_EditionBus.GetApkEditionAsync();
        }

        #endregion
    }
}